package reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo3 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
//        Person p = new Person("Xm",18);
        //通过类对象获取其表示的类的某个指定的构造器
//        cls.getConstructor();//Person()
        /*
            Constructor类的每一实例用于表示某个类上的某一个构造器
         */
        Class cls = Class.forName("reflect.Person");
        Constructor c = cls.getConstructor(String.class, int.class);
        Object o = c.newInstance("Xm", 18);
        System.out.println(o);
    }
}
